<template>
	<!-- 添加客户 -->
	<view class="addCar">
		<u-navbar title="添加客户" :background="background" title-color="#fff" back-icon-color="#fff"></u-navbar>
		<view class="addCar-bottom">
			<view class="addCar-content-box">

				<view class="addCar-carName-phone">
					<text class="addCar-phone">请输入客户名称：</text>
					<input class="addCar-input-one" type="text" placeholder="请输入客户名称" v-model="nameIpt" maxlength="15" />
				</view>
				<view class="addCar-carName-phone">
					<text class="addCar-phone">请输入客户简称：</text>
					<input class="addCar-input-one" type="text" placeholder="请输入客户简称" v-model="nameAbbreviation" maxlength="15" />
				</view>

				<view class="addCar-carName-phone">
					<text class="addCar-phone">请输入联系方式：</text>
					<input class="addCar-input-one" type="number" @input="phoneIptInput" placeholder="请输入联系方式" v-model="phoneIpt"
					 maxlength="11" />
				</view>
				<!-- <view class="addCar-carName-phone">
					<text class="addCar-phone">请输入授权额度：</text>
					<input class="addCar-input-one" @input="tareIptInput" placeholder="请输入授权额度" type="number" v-model="tareIpt" />
				</view> -->
			</view>
			<!--  -->
			<view class="addCar-reset-determine">
				<view class="addCar-reset" @click="reset">重置</view>
				<view class="addCar-determine" @click="determine">确定</view>
			</view>
		</view>
		<u-modal v-model="addCarLoginShow" content="请确认是否添加客户" :show-cancel-button="true" @confirm="addCarConfirm"></u-modal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userinfo: JSON.parse(uni.getStorageSync('userinfo')),
				background: {
					backgroundColor: '#00AAF2',
				},
				componeryArr: [],
				addressNew: null,
				Index: 0,
				diasabledInput: true, //可读不可写
				nameIpt: '', //车主姓名
				phoneIpt: '', //联系方式
				nameAbbreviation: '', //客户简称
				addCarLoginShow:false,
			}
		},
		onShow() {
		},
		methods: {
			tareIptInput() { //限制验证码长度
				if (this.tareIpt.length > 6) {
					this.tareIpt = this.tareIpt.slice(0, 6)
				}
			},
			phoneIptInput() {
				if (this.phoneIpt.length > 11) {
					this.phoneIpt = this.phoneIpt.slice(0, 11)
				}
			},
			// 确定
			determine() {
				if (this.nameIpt=='') return uni.showToast({
					title: '请输入客户名称',
					duration: 5000,
					icon: 'none',
				});
				var regP = /^1[3-9][0-9]{9}$/;
				if (this.phoneIpt == '') {
					return uni.showToast({
						title: '请输入联系方式',
						duration: 5000,
						icon: 'none',
					});
				}else{
					if (!regP.test(this.phoneIpt)) return uni.showToast({
						title: '手机号格式不正确，请检查',
						duration: 5000,
						icon: 'none',
					});
				}
				this.addCarLoginShow = true

			},
			addCarConfirm() {
				uni.request({
					url: this.baseUrl + '/orm/ormtb410/insertOrmtb410',
					method: 'POST',
					dataType: 'json',
					data: {
						ORMTB400ID: this.userinfo.ORMTB400ID,
						ORMTB410CA00: this.nameIpt,
						ORMTB410CA01: this.nameAbbreviation,
						ORMTB410CA02: this.phoneIpt,
						PERTB005CD01: this.userinfo.ORMTB400CA03,//大客户代码
						PERTB005CC01: this.userinfo.PERTB005CA02,//创建人
					},
					success: (res) => {
						console.log(res);
						if (res.data.code == 200) {
							uni.showToast({
								title: '添加成功',
								duration: 5000,
								icon: 'none',
							});
							uni.navigateBack()
						} else {
							uni.showToast({
								title: res.data.message,
								duration: 5000,
								icon: 'none',
							});
						}
					},
					fail: (res) => {
						uni.showToast({
							title: res.data.message,
							duration: 5000,
							icon: 'none',
						});
					}
				});
			},
			// 重置
			reset() {
				this.nameIpt = '' //车主姓名
				this.phoneIpt = '' //联系方式
				this.nameAbbreviation= ''
			},
		}
	}
</script>

<style scoped>
	.addCar input {
		border: 0;
	}

	.addCar {
		width: 100%;
		min-height: 100vh;
		background-color: rgba(242, 242, 242, 1);
		overflow: hidden;
	}

	/* 列表 */

	/* 内容 */
	.addCar-content-box {
		width: 100%;
		background: rgba(255, 255, 255, 1);
		padding: 0 24rpx;
	}

	.addCar-carName-phone {
		border-bottom: 2rpx solid rgba(230, 230, 230, 1);
		padding: 18rpx 0;
	}

	.addCar-input-one {
		width: 310rpx !important;
		display: inline-block;
		margin-bottom: 0 !important;
		padding: 0 !important;
		height: 44rpx !important;
		/* margin-left: 0.1rem; */
		vertical-align: middle;
		color: rgba(51, 51, 51, 1);
		font-size: 28rpx;
		text-align: center;
	}

	.addCar-phone {
		width: 238rpx;
		display: inline-block;
		font-size: 30rpx;
		color: rgba(102, 102, 102, 1);
		vertical-align: middle;
		/* background: #000000; */
	}

	.addCar-phone-placeholder {
		font-size: 30rpx;
		color: rgba(102, 102, 102, .5);
	}

	.addCar-dun {
		color: rgba(51, 51, 51, 1);
		font-size: 30rpx;
	}

	/* 按钮 */
	.addCar-reset-determine {
		margin-top: 167rpx;
		display: flex;
	}

	.addCar-reset-determine>view {
		width: 159rpx;
		text-align: center;
		line-height: 65rpx;
		color: rgba(255, 255, 255, 1);
		font-size: 32rpx;
	}

	.addCar-reset {
		width: 159rpx;
		background: rgba(234, 197, 15, 1);
		text-align: center;
		margin-left: 170rpx;
	}

	.addCar-determine {
		background: rgba(0, 161, 244, 1);
		margin-left: 60rpx;
	}

	.addCar-phone-car {
		display: inline-block;
		width: 310rpx;
		height: 44rpx;
		line-height: 44rpx;
		/* border: 1px solid rgba(0, 0, 0, .2); */
		/* border-radius: 3px; */
		text-align: center;
		vertical-align: middle;
		font-size: 30rpx;
	}

	input::placeholder {
		color: rgba(102, 102, 102, .5);
	}
</style>
